<?php

namespace Trawind\Skeleton\Providers;

use Illuminate\Redis\RedisManager;
use Illuminate\Support\ServiceProvider;
use Trawind\Basics\Commands\SystemDownCommand;
use Trawind\Basics\Commands\SystemUpCommand;
use Trawind\Basics\Commands\SystemMigrateCommand;
use Trawind\Extension\Commands\SystemBusinessTypeCommand;
use Trawind\Extension\Commands\SystemFieldCommand;
use Trawind\Skeleton\Generators\Commands\ControllerCommand;
use Trawind\Skeleton\Generators\Commands\RemoteCommand;
use Trawind\Skeleton\Generators\Commands\RepositoryCommand;
use Trawind\Skeleton\Generators\Commands\RequestCommand;
use Trawind\Skeleton\Generators\Commands\SkeletonCommand;


class RepositoryServiceProvider extends ServiceProvider
{


    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        if ($this->app->runningInConsole()) {
            $this->commands(SystemDownCommand::class);
            $this->commands(SystemUpCommand::class);
            $this->commands(SystemMigrateCommand::class);
            $this->commands(SystemFieldCommand::class);
            $this->commands(SystemBusinessTypeCommand::class);


            $this->commands(ControllerCommand::class);
            $this->commands(RepositoryCommand::class);
            $this->commands(SkeletonCommand::class);
            $this->commands(RequestCommand::class);
            $this->commands(RemoteCommand::class);
        }

        $this->app->singleton('common_redis', function ($app) {
            $config = config('database.redis');
            $config['options']['prefix'] = '';
            return new RedisManager($app, 'phpredis', $config);
        });

    }


    public function boot()
    {
        $this->loadTranslationsFrom(__DIR__.'/../assets/translations', 'trawind');

        $this->publishes([
            __DIR__.'/../assets/repository.php' => config_path('repository.php')
        ]);
    }

}